﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace DogJson
{

    public static class CollectionManager
    {
        public static void Start()
        {
            var assembly = Assembly.GetAssembly(typeof(CollectionArrayBase));

            ChakeAssembly(assembly);
            assembly = Assembly.GetExecutingAssembly();
            ChakeAssembly(assembly);
            assembly = Assembly.GetCallingAssembly();
            ChakeAssembly(assembly);
            return;
        }

        private static void ChakeAssembly(Assembly assembly)
        {
            foreach (var t in assembly.GetTypes())
            {
                CollectionAttribute attribute = t.GetCustomAttribute<CollectionAttribute>();
                if (attribute != null)
                {
                    formatterTypeMap[attribute.type] = t;
                    if (!attribute.type.IsGenericType)
                    {
                        formatterAllMap[attribute.type] = System.Activator.CreateInstance(t) as CollectionArrayBase;
                    }
                }
            }
        }

        public static readonly Dictionary<Type, Type> formatterTypeMap = new Dictionary<Type, Type>()
        {
            //{typeof(Program.V3), typeof(CollectionArrayV3)},
            //{typeof(List<>), typeof(CollectionArrayList<>)},
            //{typeof(DictionaryKV<,>), typeof(CollectionArrayDictionaryKV<,>)},
            //{typeof(Dictionary<,>), typeof(CollectionArrayDictionary<,>)},
            //{typeof(HashSet<>), typeof(CollectionArrayHashSet<>)},
            //{typeof(Queue<>), typeof(CollectionArrayQueue<>)},
            //{typeof(Stack<>), typeof(CollectionArrayStack<>)},
            //{typeof(LinkedList<>), typeof(CollectionArrayLinkedList<>)},
        };

        public static readonly Dictionary<Type, CollectionArrayBase> formatterAllMap = new Dictionary<Type, CollectionArrayBase>()
        {
            //{typeof(Program.V3), new CollectionArrayV3()}
        };


    }

}
